
/* 自定义属性指令，根据传入的按钮id，来控制是否显示按钮*/
import {Directive, Inject, Input, TemplateRef, ViewContainerRef} from '@angular/core';
import {DA_SERVICE_TOKEN, ITokenService} from '@delon/auth';

@Directive({
    selector: '[appIf]'
})
export class IfDirective {
    @Input('appIf')
    set condition(newCondition: string) {
        let funcBhvList = this.tokenService.get().funcList;
        console.log(newCondition)
        console.log(funcBhvList.indexOf(newCondition))
        if (funcBhvList.indexOf(newCondition) >= 0) { // 大于等于0，代表存在，说明有行为权限
            this.viewContainer.createEmbeddedView(this.templateRef);
        } else { // 否则说无行为权限，不可展示
            this.viewContainer.clear();
        }
    }
    constructor(private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef,
                @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,) {
    }
}
